package online.afeibaili.storebackendframework.model

import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.Table


/**
 * 订单类
 *
 *@author AfeiBaili
 *@version 2025/10/17 16:02
 */

@Entity
@Table(name = "orders")
class OrderEntity() {
    @Id
    var createTime: Long = 0
    var accountId: String = ""
    var amount: Double = 0.0
    var actualAmount: Double = 0.0
    var paymentStatus: Int = PaymentStatus.UNPAID.code
    var shippingAddress: String = ""
    var products: String = ""
    var remarks: String = ""
    var paymentTime: Long? = 0
    var shippingTime: Long? = 0
    var completionTime: Long? = 0

    constructor(accountId: String, products: String) : this() {
        createTime = System.currentTimeMillis()
        this.accountId = accountId
        this.products = products
    }

    constructor(
        accountId: String,
        products: String,
        amount: Double,
        actualAmount: Double,
        shippingAddress: String,
        remarks: String,
        paymentTime: Long? = null,
        shippingTime: Long? = null,
        completionTime: Long? = null,
    ) : this() {
        createTime = System.currentTimeMillis()
        this.accountId = accountId
        this.amount = amount
        this.products = products
        this.actualAmount = actualAmount
        this.shippingAddress = shippingAddress
        this.remarks = remarks
        this.paymentTime = paymentTime
        this.shippingTime = shippingTime
        this.completionTime = completionTime
    }

    override fun toString(): String {
        return "OrderEntity(createTime=$createTime, accountId='$accountId', paymentStatus=$paymentStatus)"
    }

}

enum class PaymentStatus(var code: Int) {
    /** 未付款 */
    UNPAID(0),

    /** 已付款 */
    PAID(1),

    /** 已完成 */
    COMPLETE(2),

    /** 正在配送 */
    IN_DELIVERY(3),

    /** 已取消 */
    CANCELLED(4),
}
